package com.it.service.impl;

import com.it.mapper.CourseOrderMapper;
import com.it.pojo.CourseOrder;
import com.it.pojo.MonthIncome;
import com.it.pojo.PageModel;
import com.it.service.IcourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hp
 */
@Service
public class IcourseOrderServiceimpl implements IcourseOrderService {
    @Autowired
    CourseOrderMapper courseOrderMapper;

    @Override
    public PageModel<CourseOrder> pageModel(CourseOrder condition, int page, int PageSize) {
        PageModel<CourseOrder> result =new PageModel<CourseOrder>();
        result.setCode(0);
        //查询参数
        Map<String, Object> param=new HashMap<String, Object>();
        /**
         * select * from t_course_order limit 0,10
         * 开始 0设置为start (Page-1)*PageSize 就是当前页展示
         */
        param.put("condition",condition);
        param.put("start",(page-1) * PageSize);
        param.put("limit",PageSize);
        //总条数
        int totalCount =courseOrderMapper.findCountByMap(param);
        result.setCount(totalCount);
        List<CourseOrder> list=courseOrderMapper.findListByMap(param);
        result.setData(list);
        return result;
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
         return  courseOrderMapper.findByOrderId(order_id);
    }

    @Override
    public void save(CourseOrder order) {
        courseOrderMapper.inSertorder(order);
    }
    @Override
    public void deleteByID(String order_id) {
        courseOrderMapper.deleteByID(order_id);
    }

    @Override
    public void upDate(CourseOrder order) {
        courseOrderMapper.upDate(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseOrderMapper.getMonthIncomes();
    }

}
